var exam = {}
exam.addExam=function (){
    $.post('exam/addExam.html',null,function (view){
        common.commonModalDialogClearSubmitButtonBind()
        common.commonModalDialog('新建考试信息',view,function (){
            $.post('exam/addSave',{name:$('#add_exam_input').val()},function (result){
                if (!result){
                    alert('考试名称重复')
                }else{
                    alert('添加成功')
                    common.commonModalDialogClose()
                    mainNavigation.examManageNavigation()
                }
            })
        })
    })
}
exam.query=function (page){
    var currentPage = page!=null?page:1
    var param = {
        name:$('#exam_name').val(),
        type:$('#exam_type').val()!='==请选择=='?$('#exam_type').val():'',
        status:$('#exam_status').val()!='==请选择=='?$('#exam_status').val():'',
        page:currentPage
    }
    var start_time_input = $('#exam_start_time').val()
    if (start_time_input==''){
        param.start_time = null
    }else {
        var start_time = new Date(start_time_input);
        var start_time_year = start_time.getFullYear()
        var start_time_month = start_time.getMonth()
        if (start_time_month+1<10){
            start_time_month = '0'+(start_time_month+1)
        }
        var start_time_day = start_time.getDate()
        if (start_time_day<10){
            start_time_day = '0'+start_time_day
        }
        param.start_time = start_time_year + '-' +start_time_month + '-' + start_time_day + ' ' + start_time.getHours() + ":" +start_time.getMinutes() +':' +start_time.getSeconds()
    }
    var end_time_input = $('#exam_end_time').val()
    if (end_time_input==''){
        param.end_time = null
    }else {
        var end_time = new Date(end_time_input);
        var end_time_year = end_time.getFullYear()
        var end_time_month = end_time.getMonth()
        if (end_time_month+1<10){
            end_time_month = '0'+(end_time_month+1)
        }
        var end_time_day = end_time.getDate()
        if (end_time_day<10){
            end_time_day = '0'+end_time_day
        }
        param.end_time = end_time_year + '-' +end_time_month + '-' + end_time_day +' '+end_time.getHours()+':'+end_time.getMinutes()+':'+end_time.getSeconds()
    }
    $.post('exam/query.html',param,function (view){
        $('#exam_part_two').html(view)
   })
}
exam.clearQuery=function (){
    $('#exam_part_one .form-inline .form-group .form-control').val('')
    exam.query()
}
exam.limitQuery=function (page){
    exam.query(page)
}
exam.editPage=function (id){
    $.post('exam/edit.html',{id:id},function (view){
        $('.context').html(view)
        //需要做一个缓存班级的查找
        studentPage.bindStudentClassDefaultShow()
    })
}
exam.return=function (){
    $.post('exam/mainPage.html',null,function (view){
        $('.context').html(view)
    })
}
exam.editName=function (id){
    common.commonModalDialogClearSubmitButtonBind()
    $.post('exam/addExam.html',{id:id},function (view){
        common.commonModalDialog('编辑考试名称',view,function (){
            $.post('exam/editName',{id:id,name:$('#add_exam_input').val()},function (result){
                if (result){
                    alert('修改成功')
                    common.commonModalDialogClose()
                    $.post('exam/edit.html',{id:id},function (view){
                        $('.context').html(view)
                    })
                }else {
                    alert('考试名称重复,请重新修改')
                }
            })
        })
    })
}
exam.relationTemplate=function (){
    $.post('template/defaultTemplateList',{examSymbol:'exam'},function (view){
        common.commonModalDialogClearSubmitButtonBind()

        common.commonModalDialog('选择模板',view,function (){
            var select = $('#template_list_body .table tbody tr td input:checked').length
            if (select==1){
                var relation_template_course = $('#template_list_body .table tbody tr td input:checked').parent().next().next().next().next().text()
                var relation_template_id = $('#template_list_body .table tbody tr td input:checked').val()
                var relation_template_name = $('#template_list_body .table tbody tr td input:checked').parent().next().next().next().text()
                common.commonModalDialogClose()
                $('#exam_relation_input').val(relation_template_name)
                $('#exam_relation_input_hidden').val(relation_template_id)
                $('#exam_relation_input_hidden_name').val(relation_template_course)
            }else {
                alert('一场考试只能关联一个模板')
            }
        })
        common.commonModalSizeSet('modal-lg')
    })
}
exam.relationTemplateInfo=function (){
    var relation_template_id = $('#exam_relation_input_hidden').val()
    if (relation_template_id==''){
        alert('请先选择想要展示的模板')
    }else {
        $.post('template/list/edit.html',{templateId:relation_template_id},function (view){
            // $('.context').html(view)
            common.commonModalDialog('模板详情',view,function (){
                common.commonModalDialogClose()
            })
            template.dynamic.scoreCompute()
            template.static.computeRightScore()
            common.commonModalSizeSet('modal-lg')
            var template_type =  $('#common-modal #modal-dialog .modal-content .common-modal-body div ul li a').text()
            if (template_type=='动态模板'){
                //设置头部禁用
                $('#common-modal #modal-dialog .modal-content .common-modal-body div .tab-pane div #mainBox #formBox .form-horizontal .form-group div .form-control').prop('disabled',true)
                //设置输入框禁用
                $('#common-modal #modal-dialog .modal-content .common-modal-body div .tab-pane div #mainBox #dynamic-template-ul li div .form-horizontal .form-group div input').prop('disabled',true)
                //删除保存按钮
                $('#common-modal #modal-dialog .modal-content .common-modal-body div div div #mainBox button').remove()
            }else{
                $('#common-modal #modal-dialog .modal-content .common-modal-body div div div #static_template_box #static_template_top_part .form-inline #static_template_top_button_group').remove()
                $('#common-modal #modal-dialog .modal-content .common-modal-body div div div #static_template_box #static_template_top_part .form-inline .form-group .form-control').prop('disabled',true)
                $('#common-modal #modal-dialog .modal-content .common-modal-body div div div #static_template_box #static_template_left_part #static_template_left_head_box #static_template_head_button_group').remove()
                $('#common-modal #modal-dialog .modal-content .common-modal-body div div div #static_template_box #static_template_left_part #static_template_left_content_box #static_template_left_content_box_inner_content div .static_template_left_content .static_template_content_edit_group ').remove()
                $('#common-modal #modal-dialog .modal-content .common-modal-body div div div #static_template_box #static_template_left_part #static_template_left_content_box #static_template_left_bottom_button_group').remove()
                $('#common-modal #modal-dialog .modal-content .common-modal-body div div div #static_template_box #static_template_left_part  #static_template_left_head_box #static_template_head_edit_group ').remove()
                $('#common-modal #modal-dialog .modal-content .common-modal-body div div div #static_template_box #static_template_right_part div div span input').prop('disabled',true)
            }
        })
    }
}
exam.selectTimeResolve=function (symbol){
    if (symbol=='区间'){
        //解封自己
        $('#exam_edit_around').prop('disabled',false)
        $('#exam_edit_start_time').prop('disabled',false)
        $('#exam_edit_end_time').prop('disabled',false)
        //封其他
        $('#exam_edit_duration_time').prop('disabled',true)
        $('#exam_edit_duration').prop('disabled',true)
    }else {
        $('#exam_edit_duration_time').prop('disabled',false)
        $('#exam_edit_duration').prop('disabled',false)

        $('#exam_edit_around').prop('disabled',true)
        $('#exam_edit_start_time').prop('disabled',true)
        $('#exam_edit_end_time').prop('disabled',true)
    }
}
exam.cancelTimeBind=function (){
    $('#exam_edit_duration_time').prop('disabled',false)
    $('#exam_edit_duration').prop('disabled',false)
    $('#exam_edit_duration').val('30分钟')

    $('#exam_edit_around').prop('disabled',false)
    $('#exam_edit_start_time').prop('disabled',false)
    $('#exam_edit_end_time').prop('disabled',false)
}
exam.selectClass=function (){
    //这个方法和之前的关联模板都有一个相似的问题  就是如果先访问student页面没有问题 如果先访问exam中的student页面 然后返回student模块页面就会出现问题  感觉是页面缓存问题，浏览器自带的刷新也可以解决  不知道如何解决
    $.post('student/studentMainPage.html',{examSymbol:'examSymbol'},function (view){
        common.commonModalDialogClearSubmitButtonBind()
        common.commonModalDialog('选择班级',view,function (){
            common.commonModalDialogClose()
        })
        common.commonModalSizeSet('modal-lg')
        //需要对student页面进行处理
        if ($('#examSymbol')!=null){
            $('#common-modal #modal-dialog .modal-content .common-modal-body #student-top-content .form-inline #student-right-top-content').remove()
            for (var i = 0;i<=1;i++){
                $('#common-modal #modal-dialog .modal-content .common-modal-body #student-bottom-content .form-inline .form-group:eq(0)').remove()
            }
            $('#common-modal #modal-dialog .modal-content .common-modal-body #student-bottom-content .form-inline button').remove()
            $('#common-modal #modal-dialog .modal-content .common-modal-body #student-bottom-content .form-inline #student-right-bottom-content').remove()
            $('#common-modal #modal-dialog .modal-content .common-modal-body #student-bottom-content .form-inline .form-group #bottom-class_no').prop('disabled',true)
            $('#common-modal #modal-dialog .modal-content .common-modal-body').css(
                {
                    height:2000//1562刚好
                }
            )
        }
        studentPage.bindStudentClassSelectAll()

    })
}
exam.definedClass=function (){
    $.post('exam/definedClass.html',null,function (view){
        common.commonModalDialogClearSubmitButtonBind()
        common.commonModalDialog('自定义班级',view,function (){
            $.post('exam/definedClassSave',{examId:$('#exam_hidden_id').val(),definedClassName:$('#exam_defined_class').val()},function (result){
                if (result){
                    alert('添加成功')
                    common.commonModalDialogClose()
                    studentPage.bindStudentClassDefaultShow()
                }else {
                    alert('班级名称重复')
                }
            })
        })
        //因为我们使用的是同一个模态框  我们在上面的选择班级中对模态框进行了处理  如果你先打开选择班级的模态框 在打开自定义班级的模态框就会出现模态框大小跟之前的一样 所以这里单独处理一下
        common.commonModalDefaultSize()
        $('#common-modal #modal-dialog .modal-content .common-modal-body').css(
            {
                height:34//默认大小
            }
        )

    })
}
exam.importClass=function (){
    common.commonModalDialogClearSubmitButtonBind()
    $.post('exam/importClass.html',null,function (view){
        common.commonModalDialog('导入班级',view,function (){
            exam.importClassSave()
        })
        //因为我们使用的是同一个模态框  我们在上面的选择班级中对模态框进行了处理  如果你先打开选择班级的模态框 在打开自定义班级的模态框就会出现模态框大小跟之前的一样 所以这里单独处理一下
        common.commonModalDefaultSize()
        $('#common-modal #modal-dialog .modal-content .common-modal-body').css(
            {
                height:34//默认大小
            }
        )
    })

}
exam.changeFileContent=function (){
    var fileContent = $('#exam_import_class').val();
    if (fileContent.endsWith('.xls') || fileContent.endsWith('.xlsx')){
        $('#fileContent').html($('#exam_import_class').val())
    }else {
        alert('请选择正确的excel文件')
    }
}
exam.importClassSave=function (){
    var file = $('#exam_import_class').prop('files')
    var formData = new FormData()
    formData.append('file',file[0])
    formData.append('examId',$('#exam_hidden_id').val())
    //发送ajax请求保存
    $.ajax({
        url:'exam/importClassSave',
        type: 'POST',
        data:formData,
        cache:false,
        processData:false,
        contentType:false,
        dataType:false,
        success:function (result){
            alert(result.replaceAll("|","\n"))
            common.commonModalDialogClose()
            studentPage.bindStudentClassDefaultShow()
        }
    })
}
exam.removeClass=function (className){
    $.post('exam/removeClass',{examId:$('#exam_hidden_id').val(),className:className},function (){
        alert('移除成功')
        studentPage.bindStudentClassDefaultShow()
    })
}
exam.importClassStudent=function (className){
    $.post('exam/importClassStudent.html',null,function (view){
        common.commonModalDialogClearSubmitButtonBind()
        common.commonModalDialog('导入学生',view,function (){
            exam.importClassStudentSave(className)
        })
        //因为我们使用的是同一个模态框  我们在上面的选择班级中对模态框进行了处理  如果你先打开选择班级的模态框 在打开自定义班级的模态框就会出现模态框大小跟之前的一样 所以这里单独处理一下
        common.commonModalDefaultSize()
        $('#common-modal #modal-dialog .modal-content .common-modal-body').css(
            {
                height:34//默认大小
            }
        )
    })
}
exam.importClassStudentSave=function(className){
    var file = $('#exam_import_class').prop('files')
    var formData = new FormData()
    formData.append('file',file[0])
    formData.append('examId',$('#exam_hidden_id').val())
    formData.append("className",className)
    //发送ajax请求保存
    $.ajax({
        url:'exam/importClassStudentSave',
        type: 'POST',
        data:formData,
        cache:false,
        processData:false,
        contentType:false,
        dataType:false,
        success:function (result){
            alert(result.replaceAll("|","\n"))
            common.commonModalDialogClose()
            studentPage.bindStudentClassDefaultShow()
        }
    })
}
exam.adjustStudent=function (className){
    $.post('exam/adjustStudent.html',{examId:$('#exam_hidden_id').val(),className:className},function (view){
        common.commonModalDialogClearSubmitButtonBind()
        common.commonModalDialog('调整【'+className+'关联学生】',view,function (){
            common.commonModalDialogClose()
        })
        //因为我们使用的是同一个模态框  我们在上面的选择班级中对模态框进行了处理  如果你先打开选择班级的模态框 在打开自定义班级的模态框就会出现模态框大小跟之前的一样 所以这里单独处理一下
        common.commonModalDefaultSize()
        common.commonModalSizeSet('modal-lg')
        $('#common-modal #modal-dialog .modal-content .common-modal-body').css(
            {
                height:34//默认大小
            }
        )
    })
}
exam.studentInfo=function (className){
    $.post('exam/adjustStudent.html',{examId:$('#exam_hidden_id').val(),className:className},function (view){
        common.commonModalDialogClearSubmitButtonBind()
        common.commonModalDialog('【'+className+'】学生详情',view,function (){
            common.commonModalDialogClose()
        })
        //因为我们使用的是同一个模态框  我们在上面的选择班级中对模态框进行了处理  如果你先打开选择班级的模态框 在打开自定义班级的模态框就会出现模态框大小跟之前的一样 所以这里单独处理一下
        common.commonModalDefaultSize()
        common.commonModalSizeSet('modal-lg')
    })
}
exam.adjustStudentSearch=function (className){
    var param = {
        examId:$('#exam_hidden_id').val(),
        currentClassName:className,
        searchClassName:$('#adjustStudentSearch').val()
    }
    $.post('exam/adjustStudentSearch.html',param,function (view){
        $('#noneRelationTable').replaceWith(view)
    })
}
exam.adjustStudentBind=function (currentStudentCode){
    var param={
        examId:$('#exam_hidden_id').val(),
        currentStudentCode:currentStudentCode,
        className:$('#adjustStudentClassName').val(),
        searchClassName:$('#adjustStudentSearch').val()
    }
    $.post('exam/adjustStudentBind',param,function (view){
        alert('绑定成功')
        $('#adjustStudentContent').replaceWith(view)
        studentPage.bindStudentClassDefaultShow()
    })
}
exam.adjustStudentUnBind=function (currentStudentCode){
    var param={
        examId:$('#exam_hidden_id').val(),
        currentStudentCode:currentStudentCode,
        className:$('#adjustStudentClassName').val(),
        searchClassName:$('#adjustStudentSearch').val()
    }
    $.post('exam/adjustStudentUnBind',param,function (view){
        alert('解绑成功')
        $('#adjustStudentContent').replaceWith(view)
        studentPage.bindStudentClassDefaultShow()
    })
}
exam.editSave=function (){
    var param = {
        id:$('#exam_hidden_id').val(),
        name:$('#exam_hidden_name').val(),
        course:$('#exam_relation_input_hidden_name').val(),
        yuliu1:$('#exam_relation_input').val(),
        template_id:$('#exam_relation_input_hidden').val()
    }
    if ($('#exam_edit_table table tbody tr').length==0){
        alert('请选择想要添加的班级')
        return;
    }
    var time_around = $('#exam_edit_around_time .form-group #exam_edit_around').prop('checked')
    var time_difined = $('#exam_edit_defined_time .form-group #exam_edit_duration_time').prop('checked')
    if (time_around){
        var start_time = $('#exam_edit_around_time .form-group #exam_edit_around').parent().parent().next().children('.form-group').children('span').children('#exam_edit_start_time').val()
        var start_time_obj = new Date(start_time);
        var start_time_year = start_time_obj.getFullYear()
        var start_time_month = start_time_obj.getMonth()
        if (start_time_month+1<10){
            start_time_month = '0'+(start_time_month+1)
        }
        var start_time_day = start_time_obj.getDate()
        if (start_time_day<10){
            start_time_day = '0'+start_time_day
        }
        param.start_time = start_time_year + '-' +start_time_month + '-' + start_time_day + ' ' +start_time_obj.getHours()+':'+start_time_obj.getMinutes()
        var end_time = $('#exam_edit_around_time .form-group #exam_edit_around').parent().parent().next().children('.form-group').children('span').children('#exam_edit_end_time').val()
        var end_time_obj = new Date(end_time);
        var end_time_year = end_time_obj.getFullYear()
        var end_time_month = end_time_obj.getMonth()
        if (end_time_month+1<10){
            end_time_month = '0'+(end_time_month+1)
        }
        var end_time_day = end_time_obj.getDate()
        if (end_time_day<10){
            end_time_day = '0'+end_time_day
        }
        param.end_time = end_time_year + '-' +end_time_month + '-' + end_time_day + ' ' +end_time_obj.getHours()+':'+end_time_obj.getMinutes()
    }
    if (time_difined){
        param.duration=$('#exam_edit_duration').val().replace('分钟','')
    }
    if (!time_around && !time_difined){
        alert('请选择考试时间')
        return;
    }
    $.post('exam/editSave',param,function (result){
        alert(result)
        mainNavigation.examManageNavigation()
    })
}
//未发布状态修改
exam.changeStatus1=function (ev,examId){
    var event = ev || event;
    var xPosition = event.clientX;
    var yPosition = event.clientY;
    var div = $(`<div onmouseleave="this.remove()">
                    <div onclick="exam.generatePaper(`+examId+`)" style="padding-left: 20px"><span class="glyphicon glyphicon-book"></span><a href="javascript:void(0)">生成考卷</a></div>
                    <div onclick="exam.releaseExam(`+examId+`)" style="padding-left: 20px"><span class="glyphicon glyphicon-bullhorn"></span><a>发布考试</a> </div>
                    <div onclick="exam.removeExamPage(`+examId+`)" style="padding-left: 20px"><span class="glyphicon glyphicon-remove"></span><a>删除考卷</a></div>
                    <div onclick="exam.removeExam(`+examId+`)" style="padding-left: 20px"><span class="glyphicon glyphicon-remove"></span><a>删除考试</a></div>
                </div>`)
    div.css({
        position:'absolute',
        left:xPosition,
        top:yPosition,
        height:'80',
        width:'130',
        background:'#ccc',
    })
    $('.context').append(div)

    return false;//取消浏览器默认行为
}
//未考试状态修改
exam.changeStatus2=function (ev,examId){
    var event = ev || event;
    var xPosition = event.clientX;
    var yPosition = event.clientY;
    var div = $(`<div onmouseleave="this.remove()">
                    <div onclick="exam.finishExam(`+examId+`)" style="padding-left: 20px"><span class="glyphicon glyphicon-remove"></span><a>结束考试</a></div>
                    <div onclick="exam.abandonExam(`+examId+`)" style="padding-left: 20px"><span class="glyphicon glyphicon-minus-sign"></span><a>丢弃考试</a></div>
                </div>`)
    div.css({
        position:'absolute',
        left:xPosition,
        top:yPosition,
        height:'80',
        width:'130',
        background:'#ccc',
    })
    $('.context').append(div)

    return false;//取消浏览器默认行为
}
//考试中状态修改
exam.changeStatus3=function (ev,examId){
    var event = ev || event;
    var xPosition = event.clientX;
    var yPosition = event.clientY;
    var div = $(`<div onmouseleave="this.remove()">
                    <div onclick="exam.finishExam(`+examId+`)" style="padding-left: 20px"><span class="glyphicon glyphicon-book"></span><a href="javascript:void(0)">结束考试</a></div>
                </div>`)
    div.css({
        position:'absolute',
        left:xPosition,
        top:yPosition,
        height:'80',
        width:'130',
        background:'#ccc',
    })
    $('.context').append(div)

    return false;//取消浏览器默认行为
}
//已完成状态修改
exam.changeStatus4=function (ev,examId){
    var event = ev || event;
    var xPosition = event.clientX;
    var yPosition = event.clientY;
    var div = $(`<div onmouseleave="this.remove()">
                    <div onclick="exam.lookExamPage(`+examId+`)" style="padding-left: 20px"><span class="glyphicon glyphicon-book"></span><a href="javascript:void(0)">查阅考卷</a></div>
                    <div onclick="exam.abandonExam(`+examId+`)" style="padding-left: 20px"><span class="glyphicon glyphicon-bullhorn"></span><a>丢弃考试</a> </div>
                </div>`)
    div.css({
        position:'absolute',
        left:xPosition,
        top:yPosition,
        height:'80',
        width:'130',
        background:'#ccc',
    })
    $('.context').append(div)

    return false;//取消浏览器默认行为
}
//丢弃状态修改 没有操作
exam.removeExamPage=function (examId){
    if (confirm('是否需要删除当前考试相关的考卷')){
        $.post('exam/removeExamPage',{examId:examId},function (){
            alert('删除成功')
        })
    }
}
exam.removeExam=function (examId){
    if (confirm('是否需要删除当前考试,已经关联考卷')){
        $.post('exam/removeExam',{examId:examId},function (){
            alert('删除成功')
            exam.query()
        })
    }
}
exam.releaseExam=function (examId){
    if ('是否确认发布考试,发布后,不能修改考试内容'){
        $.post('exam/releaseExam',{examId:examId},function (f){
            //有失败的可能 现在就是考试考卷没有生成 不能发布
            if (f){
                alert('发布成功')
                exam.query()
            }else {
                alert('当前考试没有生成考卷')
            }

        })
    }

}
exam.finishExam=function (examId){
    $.post('exam/finishExam',{examId:examId},function (result){
        if (!result){
            alert('不能手动结束一个区间考试')
        }else {
            alert('设置成功')
        }
        exam.query(1)
    })
}
exam.abandonExam =function (examId){
    if (confirm('是否丢弃考试,丢弃不可找回,不可使用')){
        $.post('exam/abandonExam',{examId:examId},function (){
            alert('丢弃成功')
            exam.query(1)
        })
    }

}
exam.lookExamPage = function (examId){
    $.post('exam/updateExamPaper.html',{examId:examId},function (view){
        $('.context').html(view)
    })
}
exam.readOneStudentExamPaper = function (studentId){
    var examId = $('#exam_id').val()
    $.post('exam/readOneStudentExamPaper.html',{examId:examId,studentId:studentId},function (view){
        $('.context').html(view)
    })
}
exam.examPaper_studentList = function (examId,className){
   $.post('exam/examPaperStudentList.html',{examId:examId,className:className},function (view){
       $('#examPaper_student_table').html(view)
   })
}
exam.paperReturn = function (){
    exam.lookExamPage($('#examId').val())
}
exam.updateStudentExamStatus = function (studentId,self){
    var examId = $('#exam_id').val();
    var status = $('#exam_student_list_status').val();
    var class_name = $(self).parent().parent().children().eq(3).text()
    $.post('exam/updateExamStudentState',{examId:examId,studentId:studentId,status:status},function (){
       alert('修改成功')
       exam.examPaper_studentList(examId,class_name)
    })


}
exam.generatePaper=function (examId){
    if (confirm('是否需要生成考卷')){
        //首先创建一个背景
        $.post('exam/generatePaper',{examId:examId},function (result){
            if (result){
                var progress = $(`<div class="progress">
                <div class="progress-bar progress-bar-danger progress-bar-striped" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%">
                     <span class="sr-only">80% Complete (danger)</span>
                 </div>
               </div>`)
                common.commonModalDialogClearSubmitButtonBind()
                common.commonModalDialog('上传进度',progress,null)
                $('.modal-footer').remove()

                var upload_progress = 0
                var interval = setInterval(function (){
                    if (upload_progress>=100){
                        clearInterval(interval)
                        common.commonModalDialogClose()
                        alert('生成成功')
                        return
                    }
                    upload_progress = upload_progress + 50
                    progress.css({
                        width: upload_progress+'%',
                        background: 'red'
                    })
                },500)

            }else {
                alert('不能重复生成考卷')
            }
        })

    }

}
var separator = '}-|-{'
//这个方法有一个bug 为什么数据存储到数据库 多刷新几次 数据库数据又变回初始数据
exam.examStudentScoreChange = function (){
    var examId = $('#examId').val();
    var studentId = $('#examStudentId').val()
    var student_question_score = ''
    var student_question_totalScore = 0
    //改变一个分数冉获取所有的题型的分数 数据库一起改变  页面改变总分
    $('#student_examPaper_content .questionBox .question .question-title div .form-control').each(function (i,input){
        student_question_score = student_question_score + input.value +separator
        student_question_totalScore= student_question_totalScore + parseInt(input.value)
    })
    //更新前端页面总分
    $('#student_examPaper_right #student_examPaper_right_score b').text('总分：'+student_question_totalScore+'分')
    console.log(examId+'--'+studentId+'--'+student_question_score+'--'+student_question_totalScore)
    //更新数据库
    $.post('exam/flushExamStudentScore',{exam_id:examId,student_id:studentId,yuliu2:student_question_score,score:student_question_totalScore})
}
var curr_review_edit
exam.review = function(self){
    //先判断是什么类型的题 因为批阅的·1class 氛围 review4 和 review5
     var type = $(self).parent().parent().children().eq(0).text()
     var reviewInfo ;
     var type4;
     var type5;
     if (type.indexOf('填空题')!=-1){
         reviewInfo = $(self).parent().parent().parent().children('.options').children('.review4').text()
         type4 = '填空题'
     }else if (type.indexOf('综合题')!=-1){
         reviewInfo = $(self).parent().parent().parent().children('.options').children('.review5').text()
         type5 = '综合题'
     }
     //打开模态框 展示   修改的话 需要将当前题型的所有review拼接起来 一起存储到后端
    var div = $('<div id="reviewDiv" type="text"></div>')
    var resultReview = '';//最后所有题型的批阅
    common.commonModalDialog('批阅试题',div,function (){
        //设置当前题的批阅
        if (type4!=undefined || type4!=null){
            $(self).parent().parent().parent().children('.options').children('.review4').text(curr_review_edit.txt.text())
        }
        if (type5!=undefined || type5!=null){
            $(self).parent().parent().parent().children('.options').children('.review5').text(curr_review_edit.txt.text())
        }
        //获取当前题型的所有批阅 然后保存
        $('#student_examPaper_content .questionBox .question .question-title b').each(function (i,b){
            if (type4!=undefined || type4!=null){
                //当前批阅的是填空题 需要获取所有的填空题批阅
                if (b.innerText.indexOf('填空题')!=-1){
                    resultReview = resultReview + $(b).parent().parent().children('.options').children('.review4').text()+separator
                }
            }
            if (type5!=undefined || type5!=null){
                //当前批阅的是综合题 需要获取所有的填空题批阅
                if (b.innerText.indexOf('综合题')!=-1){
                    resultReview = resultReview + $(b).parent().parent().children('.options').children('.review5').text()+separator
                }
            }
        })
        var param = {}
        if (type4!=undefined || type4!=null){
            param.review4 = resultReview
        }
        if (type5!=undefined || type5!=null){
            param.review5 = resultReview
        }
        param.exam_id = $('#examId').val()
        param.student_id = $('#examStudentId').val()
        $.post('exam/reviewSave',param)
        common.commonModalDialogClose()
    })
     if ($('#examSubmitStatus').val()=='提交'){
        common.commonModalDialogBottomClose()
     }
     curr_review_edit = new E('#reviewDiv');
     curr_review_edit.create()
     curr_review_edit.txt.html(reviewInfo)

}
exam.examPaperSubmit = function (){
    if (confirm('是否确认提交所有考试信息,提交后不可修改')){
        $.post('exam/examPaperSubmit',{examId:$('#exam_id').val()},function (){
            alert('提交成功')
            mainNavigation.examManageNavigation()
        })
    }
}
